﻿using System.Collections.Generic;
using System.Linq;
using Citi.ReportManager.Domain;

namespace Citi.ReportManager.WebUi.Models
{
    public class CategoryModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Favorite { get; set; }
        public int? ParentId { get; set; }
        public List<CategoryModel> Children { get; set; }

        public CategoryModel CreateModel(Category domain)
        {
            return new CategoryModel
            {
                Id = domain.Id,
                Name = domain.Name,
                ParentId = domain.ParentId,
                Children = CreateModel(domain.Children)                
            };
        }

        public List<CategoryModel> CreateModel(IEnumerable<Category> domain)
        {
            return domain.Select(CreateModel).ToList();
        }

        public Category CreateDomain(CategoryModel model)
        {
            return new Category
            {
                Id = model.Id,
                Name = model.Name,
                ParentId = model.ParentId
                //Children = CreateDomain(model.Children)
            };
        }

        public IEnumerable<Category> CreateDomain(IEnumerable<CategoryModel> model)
        {
            return model.Select(CreateDomain);
        }
    }
}